//
//  GetAFN.m
//  Happy Kitchen
//
//  Created by dlios on 15/3/7.
//  Copyright (c) 2015年 mac_chen. All rights reserved.
//

#import "GetAFN.h"

@implementation GetAFN
//实现自定义方法(封装AFN)
+ (instancetype)downLoadBlock:(NSString *)urlStr block:(afnBlock)myBlock
{
    GetAFN *afnDownLoad = [[GetAFN alloc] init];
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    //接口类型
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html", nil];
    //数据请求
    [manager GET:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [netWorkManager stopMonitoring];
        myBlock(responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"当前网络不给力！" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alerView show];
        
        NSLog(@"数据请求失败");
        return;
    }];
    return afnDownLoad;

}


@end
